﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ArxivatDeDocuments.ObjectesDeDades;

namespace ArxivatDeDocuments.Formularis
{
    public partial class frmOmplirNomsInexistents : Form
    {

        private List<Client> clients;
        
        private void addClientsDadesInvalides(String NIF, string Nom)
        {
            dataGridView.Rows.Add(new object[] {NIF, Nom});
        }

        public bool CancelPressed { get; private set; }


        public frmOmplirNomsInexistents(List<Client> pClients)
        {
            InitializeComponent();

            clients = pClients;

            foreach (Client c in clients)
            {
                addClientsDadesInvalides(c.Nif, c.Nom);
            }

            CancelPressed = false;
        }

        private void cmdFinalitzar_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow r in dataGridView.Rows)
            {
                Client client = (from Client c in clients where c.Nif == (string)r.Cells[0].Value select c).FirstOrDefault();
                if (client != null) client.Nom = (string)r.Cells[1].Value;
            }

            if ((from Client c in clients where string.IsNullOrEmpty(c.Nom) select c).Count() > 0)
            {
                if (MessageBox.Show("Encara hi ha clients sense nom. Si continua els documents corresponents a aquests clients no s'arxivaran. Vol Continuar ?", "Clients sense nom", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    CancelPressed = false;
                    this.Close();
                }
            }
            else
            {
                CancelPressed = false;
                this.Close();
            }

        }

        private void cmdCancelar_Click(object sender, EventArgs e)
        {
            CancelPressed = true;
            this.Close();
        }

    }
}
